package com.yz.food.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yz.food.dao.RecipesMapper;
import com.yz.food.pojo.Recipes;
import com.yz.food.service.RecipesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RecipesServiceImpl implements RecipesService {
    @Autowired
    private RecipesMapper recipesMapper;

    /**
     * 从数据库随机取
     * @return
     */
    @Override
    public List<Recipes> getRandom() {
        return recipesMapper.getRandom();
    }

    /**
     * 查询详情
     * @param recipesId
     * @return
     */
    @Override
    public Recipes getById(Integer recipesId) {
        return recipesMapper.selectByPrimaryKey(recipesId);
    }

    /**
     * 获取所有
     * @return
     */
    @Override
    public PageInfo<Recipes> getAll(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Recipes> recipes = recipesMapper.getAll();
        PageInfo helper = new PageInfo(recipes);
        return helper;
    }
}
